#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	FILE *in, *out;
	int ch;
	if (argc!=3)
	{
		fprintf(stderr,"Usage: filecopy in_file out_file\n");
		exit(	EXIT_FAILURE);
	}
	else
	{		
		printf("Copy file %s to %s\n",argv[1],argv[2]);
	}

	if ((in=fopen(argv[1],"rb"))==NULL)
	{
		fprintf(stderr,"Can't open %s\n",argv[1]);
		exit(	EXIT_FAILURE);
	}
	if ((out=fopen(argv[2],"wb"))==NULL)
	{
		fprintf(stderr,"Can't open %s\n",argv[2]);
		exit(	EXIT_FAILURE);
	}
	while ((ch=getc(in))!=EOF)
	{
		if(putc(ch,out)==EOF)
			break;
	}
	if (ferror(in))
	{
		printf("Error while reading source file.\n");
	}
	if (ferror(out))
	{
		printf("Error while reading dest file.\n");
	}
	fclose(in);
	fclose(out);
	return 0;
}
